﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.DAO;

namespace br.com.SistemaChamados.Controller
{
    public class CallCategoryController
    {
        /// <summary>
        /// Método que insere uma categoria de chamado
        /// </summary>
        /// <param name="callCategory">Categoria a ser inserida na base de dados</param>
        /// <returns>EnumCRUDState</returns>
        public EnumCRUDState InsertCallCategory(CallCategory callCategory)
        {
            EnumCRUDState stateTransaction = EnumCRUDState.SQL_NOTHING;
            try
            {
                stateTransaction = CallCategoryDAO.InsertCallCategory(callCategory);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumCRUDState.SQL_NOTHING;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método que atualiza uma categoria de chamados
        /// </summary>
        /// <param name="callCategory">A categoria com os dados a serem atualizados</param>
        /// <returns>EnumCRUDState</returns>
        public EnumCRUDState UpdateCallCategory(CallCategory callCategory)
        {
            EnumCRUDState stateTransaction = EnumCRUDState.SQL_NOTHING;
            try
            {
                stateTransaction = CallCategoryDAO.UpdateCallCategory(callCategory);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumCRUDState.SQL_NOTHING;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método para remover uma categoria de chamado da base de dados
        /// </summary>
        /// <param name="callCategory">Categoria de chamado a ser removida</param>
        /// <returns>EnumCRUDState</returns>
        public EnumCRUDState DeleteCallCategory(CallCategory callCategory)
        {
            EnumCRUDState stateTransaction = EnumCRUDState.SQL_NOTHING;
            try
            {
                stateTransaction = CallCategoryDAO.DeleteCallCategory(callCategory);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumCRUDState.SQL_ERROR;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método para selecionar uma categoria de chamado pelo seu Id
        /// </summary>
        /// <param name="callCategory">A categoria de chamado com o Id que se deseja obter</param>
        /// <returns>CallCategory</returns>
        public CallCategory GetCallCategory(CallCategory callCategory)
        {
            CallCategory ValidateCallCategorySelected = new CallCategory();
            try
            {
                ValidateCallCategorySelected = CallCategoryDAO.getCallCategory(callCategory.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ValidateCallCategorySelected;
        }

        /// <summary>
        /// Método para pegar todas as categorias de chamados da base de dados
        /// </summary>
        /// <returns>List<CallCategory></returns>
        public List<CallCategory> GetCallCategories()
        {
            List<CallCategory> Returnedlist = new List<CallCategory>();

            try
            {
                Returnedlist = CallCategoryDAO.getCallCategories();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Returnedlist;
        }

    }
}